<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="app" uri="/application" %>
<%@ taglib  prefix="s"  uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>权限设置</title>
<link href="/css/role.css" rel="stylesheet" type="text/css" />
</head>
<body>
<!-- title -->
<div class="right_title">
<div class="h"><span>系统模块-</span><a href="/role/menu_manager.shtml">菜单管理</a>  <span><a href="/role/role_manager.shtml">角色设置</a></span>  <span><a href="/role/role_menu.shtml">角色菜单</a></span> <span><a href="/role/auth_manager.shtml">权限管理</a></span>  <span><a href="/role/role_auth.shtml">角色权限</a></span> </div>
</div>
<!-- title end -->
<div class="zdgl xz_pad" style="border:0px solid red;">
  <form action="/role/setMenuByRole.shtml" name="pst" method="post">
  <div>
     选择用户角色：<select name="id" id="position" onchange="ck_check(this);" style="width:300px;">
        <option value="">请选择...</option>
        <c:forEach items="${list}" var="role">
          		<option value="${role.roleId}">${role.roleName}</option>
        </c:forEach>
      </select>
  </div>

  
  <div class="d_01">
     
  
    <c:forEach items="${clist}" var="c">
        <div>
        <h3 style="margin:0;clear:both;"><span class="shi" onclick="cg('${c.id}_div',this)">&nbsp;&nbsp;</span>${c.menuName} <input type="checkbox" name="ids" onclick="ca('${c.id}',this);" value="${c.id}" id="${c.id}_ck" /></h3>
        <dl style="padding-left:0px;display:none;" id="${c.id}_div">
        <c:forEach items="${c.list}" var="m">
           
                <dt style="margin:0;clear:both;padding:0;"><span class="yi">&nbsp;&nbsp;</span><span class="shi" onclick="bcg('dd',${m.id},this)">&nbsp;&nbsp;</span><input type="checkbox" name="ids" onclick="ca('${m.id}',this);ac('${c.id}');" value="${m.id}" pid="${c.id}" id="${m.id}_ck" />${m.menuName}</dt>
                
                <c:forEach items="${m.list}" var="son">
                       <dd parent="${m.id}" style="margin:0;clear:both;text-indent: 0px;display:none;"><span class="yi">&nbsp;&nbsp;</span><span class="yi">&nbsp;&nbsp;</span>
                       <c:choose><c:when test="${fn:length(son.list)>0}"><span class="shi" onclick="bcg('dd',${son.id},this)" ></span></c:when><c:otherwise><span class="yi">&nbsp;&nbsp;</span></c:otherwise></c:choose>
                       <input type="checkbox" onclick="ac('${m.id}');ca(${son.id},this,'operIds');"  name="ids" id="${son.id}_ck" value="${son.id}" pid="${m.id}" />${son.menuName}(${son.menuHref})</dd> 
                </c:forEach>
                
        </c:forEach>
        </dl>
        </div>
    </c:forEach>
    

  </div>

  <div class="clear0"></div>
  <div class="subd"><input type="button" value="保存菜单设置 " onclick="save_do()" /></div>
  </form>
  <div id="boxId" style="position: absolute;background: red;display:none;"><span style="color:#fff;">正在加载...</span></div>
</div>
<!-- table end -->


</body>
</html>
<script type="text/javascript" src="/scripts/util.js"></script>
<script type="text/javascript" src="/scripts/xhr.js"/></script>
<script type="text/javascript" src="/scripts/head_search.js"/></script>
<script type="text/javascript" >
   function cg(id,th){
     var o = util.$(id);
     if(o){
       o.style.display=o.style.display=='none'?'':'none';
       th.className=o.style.display=='none'?'shi':'shiyi';
     }
   }
   function bcg(tag,id,th){
      var r = document.getElementsByTagName(tag);
      var nr = filterpid(r,id);
      util.each(nr,function(e,i){
         e.style.display=e.style.display=='none'?'':'none';
         (i==0)&&(th.className==e.style.display=='none'?'shi':'shiyi');
      })
   }
   function filterpid(r,id){
      var nr=[];
      util.each(r,function(e){
         if(e.getAttribute('parent')==id){
            nr.push(e);
         }
      });
      return nr;
   }
   
  function ca(id,th,nm){
     var nm = nm||"ids";
     var r = filterCk(document.getElementsByName(nm),id);
     util.each(r,function(e){
       e.checked=th.checked;
       ca(e.value,e);
     });
  }
  function ac(id,nm){
    var nm = nm||"ids";
    var r = filterCk(document.getElementsByName(nm),id);
    var b = false;
    util.each(r,function(e){
        if(e.checked){
          b=true;
          return 1;
        }
    });
    var t = util.$(id+'_ck');
    t&&(t.checked=b);
    t&&(nm=="operIds")&&(ac(t.getAttribute("pid")));
  }
  function filterCk(list,id){
    var r=[];
    util.each(list,function(e){
      (e.getAttribute('pid')==id)&&r.push(e);
    });
    return r;
  }
  function ck_check(th){
      if(th.value!=""){
         util.dusk_div("boxId");
         function callback(d){
            util.close_dusk("boxId");
            var o = eval("("+d+")");
            checkDo("ids",o.menuReg||"");
         }
         new xhr("/role/loadMenuByRole.shtml",callback).setParameter("id",th.value).execute();
      }
  }
  function checkDo(name,reg){
     var r = document.getElementsByName(name);
     var regxp = new RegExp("^("+reg+")$");
     util.each(r,function(e){
        e.checked = regxp.test(e.value);
     })
  }
  function save_do(){
    if(confirm("确定保存该设置?")){
       var position = util.$('position');
       if(position&&position.value!=""){
         document.pst.submit();
       }else{
         alert("请选择一设置菜单的角色!");
       }
    }
  }
  
</script>


